package top.roadvast.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;

import java.util.List;

/**
 * @Author 郭泽鹏
 * @Date 2022/3/21 22:56
 * @Version 1.0
 * @Description 查询流程实例（查询业务主键）
 */
public class ProcessInstanceQuery {
//    public static void main(String[] args) {
//        final ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
//        final RuntimeService runtimeService = defaultProcessEngine.getRuntimeService();
//        //流程实例查询
//        final org.activiti.engine.runtime.ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery();
//        //获取流程实例
//        final ProcessInstance processInstance = processInstanceQuery.processInstanceId("50001").singleResult();
//        //获取业务主键
//        final String businessKey = processInstance.getBusinessKey();
//        System.out.println(businessKey);
//    }

    public static void main(String[] args) {
        final ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        final RuntimeService runtimeService = defaultProcessEngine.getRuntimeService();
        //流程实例查询
        final org.activiti.engine.runtime.ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery();
        //获取所有的流程实例
        final List<ProcessInstance> holiday = processInstanceQuery.processDefinitionKey("holiday-uel").list();
        for (ProcessInstance processInstance : holiday) {
            System.out.println("流程实例ID：" + processInstance.getProcessInstanceId());
            System.out.println("业务主键：" + processInstance.getBusinessKey());
            System.out.println("部署ID：" + processInstance.getDeploymentId());
        }
    }
}
